package com.zyasdk.enums;

import com.zyasdk.util.Base64;
import com.zyasdk.util.SP;
import com.zyasdk.util.StaticSetting;
import com.zyasdk.util.Util;

import android.content.Context;
import android.text.TextUtils;

public enum KVType {
	/**
	 * 渠道KEY
	 */
	CHANNELKEY {
		@Override
		protected String getKey() {
			return PREFIX + "CHANNELKEY";
		}
	},
	/**
	 * 渠道包KEY
	 */
	PACKAGEKEY {
		@Override
		protected String getKey() {
			return PREFIX + "PACKAGEKEY";
		}
	},
	/**
	 * 渠道包ID
	 */
	PACKID {
		@Override
		protected String getKey() {
			return PREFIX + "PACKID";
		}

		@Override
		public String getValue(Context context) {
			String value = SP.get(context, getKey());
			if (TextUtils.isEmpty(value)) {
				return DEFAULT_PACKID;
			}
			return value;
		}

		public boolean isAuto(Context context) {
			return getValue(context).equals(DEFAULT_PACKID);
		}
	},
	/**
	 * 项目KEY
	 */
	PBINDKEY {
		@Override
		protected String getKey() {
			return PREFIX + "PBINDKEY";
		}

		@Override
		public String getValue(Context context) {
			String value = SP.get(context, getKey());
			if (TextUtils.isEmpty(value)) {
				return new String(Base64.decode(
						Util.toStringHex(StaticSetting.PROJECTBINDKEY)
								.getBytes(), Base64.DEFAULT));
			}
			return value;
		}

	},
	NEWSINTERVAL {

		@Override
		protected String getKey() {
			return PREFIX + "NEWSINTERVAL";
		}

		@Override
		public String getValue(Context context) {
			return SP.get(context, getKey());
		}
	};
	protected abstract String getKey();

	public String getValue(Context context) {
		return SP.get(context, getKey());
	}

	public void setValue(Context context, String value) {
		SP.put(context, getKey(), value);
	}

	public boolean isAuto(Context context) {
		return false;
	}

	private static String DEFAULT_PACKID = "12";
	private static String PREFIX = "ZYASDKXXX_";
}